<template>
<div class="page_list" ref="page_list" v-loading='loading' element-loading-background="rgba(0, 0, 0, 0.5)" element-loading-text="正在加载">
  <div class="top_bar">
    <div :class="[thisActive==item.id?'typeAct':'','type_item']" v-for="item in typeList" :key="item.id" @click="changeType(item.id)">{{item.type_name}}</div>
  </div>
  <div class="zhan"></div>
  <van-pull-refresh v-if="typeList.length>0" class="refresh_div" v-model="refreshing" @refresh="onRefresh">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      class="list_div"
      @load="onLoad"
    >
      <div class="flex_w">
        <div class="item" v-for="(item,index) in list" :key="index" @click="toDetail(item.url)">
          <div class="title">{{item.title}}</div>
          <div class="time flex_sb">
            <div>{{item.createtime}}</div>
            <div style="color:#666">{{item.froms||'-'}}</div>
          </div>
        </div>
      </div>
    </van-list>
  </van-pull-refresh>
</div>
</template>
<script>
import {GetOpinionsTypeList, GetOpinionsList} from '@/api/api'
export default {
  data(){
    return{
      list:[],
      typeList:[],
      thisActive:'',
      page:0,
      loading:false,
      finished: false,
      refreshing: false,
      scrollTop:0
    }
  }, 
  activated(){
    this.$refs.page_list.scrollTop =  this.top 
  },
  created(){
    GetOpinionsTypeList({id:localStorage.indexId}).then(res=>{
      this.typeList=res.data.data
      this.thisActive=res.data.data[0].id
    })
  },
  methods:{
    toDetail(url){
      this.top = this.$refs.page_list.scrollTop   
      window.location.href = url
    },
    changeType(id){
      this.finished = false
      this.list = []
      this.thisActive=id
      this.page = 0
      this.onLoad()
    },
    onLoad(){
      this.page += 1
      GetOpinionsList({type_id:this.thisActive,page:this.page,id:localStorage.indexId}).then(res=>{
        this.list=res.data.data
        if(res.data.length==0){
          this.loading = false
          this.finished = true
          this.refreshing = false
          this.list = []
          return
        }
        if(this.page==1){
          this.list = res.data.data
        }else{
          this.list = this.list.concat(res.data.data)
        }
        this.loading = false
        this.refreshing=false
        if(res.data.per_page<=this.page){
          this.finished = true
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.page_list{
  height: 100%;
  overflow: auto;
  background: #f3f3f3;
}
.zhan{
  width: 100%;
  height: 50px;
}
.top_bar{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 100;
  height: 50px;
  overflow-x: auto;
  background: #fff;
  line-height: 50px;
  white-space: nowrap;
  box-shadow: 0 4px 10px 0 rgba($color: #000000, $alpha: .2);
  &::-webkit-scrollbar {
    width: 0 !important;
  }
  &::-webkit-scrollbar {
    width: 0 !important;height: 0;
  }
  .typeAct{
    font-size: 17px !important;
    font-weight:800;
    color: #f93;
  }
  .type_item{
    margin: 0 10px;
    font-size: 15px;
    display: inline-block;
  }
}
.item{
  width: calc(100% - 30px);
  margin: 6px 15px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 4px 10px 0 rgba($color: #000000, $alpha: .2);
  padding: 10px;
  .time{
    font-size: 14px;
    color: #999;
  }
  .title{
    // font-weight: 600;
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
  }
}
</style>